package com.dbs.donatebooksystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dbs.donatebooksystem.pojo.Book;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface booksMapper  extends BaseMapper<Book> {
//插入书籍
@Insert("INSERT INTO books(id, user_id, bookname, conditions, usages, page_count, photo_url, trace_code, books_code, category, pub_address) " +
        "VALUES (#{book.id}, #{book.userId}, #{book.bookname}, #{book.conditions}, #{book.usages}, " +
        "#{book.pageCount}, #{book.photoUrl}, #{book.traceCode}, #{book.booksCode}, " +
        "#{book.category}, #{book.pubAddress})")
void insertBook(@Param("book") Book book);
    //批量查询书籍

    List<Book> SelectBooks(@Param("bookname")String bookname, @Param("category")String category);
//单个书籍查询


     List<Book> list(@Param("bookname")String bookname, @Param("category")String category);

    @Select("SELECT category, COUNT(*) AS count FROM books GROUP BY category")
    List<Map<String, Object>> selectCategoryNum();


    List<Book> searchBooks(@Param("searchBook") Book searchBook);

    @Select("select id from books where bookname  = #{book.bookname}")
    int getByName(@Param("book")Book book);

    @Select("select * from books where id=#{id}")
    Book selectBookById(@Param("id") Integer id);
}
